﻿@using Xunit;
@inherits TestContext
@code
{
    public FluentGridTests()
    {
        this.JSInterop.Mode = JSRuntimeMode.Loose;
    }

    [Fact]
    public void FluentGrid_Default()
    {
        // Arrange && Act
        var cut = Render(@<FluentGrid>My content</FluentGrid>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentGrid_SpacingJustify()
    {
        // Arrange && Act
        var cut = Render(@<FluentGrid Spacing="5" Justify="JustifyContent.Center">My content</FluentGrid>);

        //Assert
        cut.Verify();
    }

    [Fact]
    public void FluentGrid_Items_Default()
    {
        // Arrange && Act
        var cut = Render(
            @<FluentGrid>
                <FluentGridItem xs="6" md="6">Cell 1</FluentGridItem>
                <FluentGridItem xs="6" md="6">Cell 2</FluentGridItem>
            </FluentGrid>);

        //Assert
        cut.Verify();
    }

    [Fact]
    public void FluentGrid_Items_AllBreakpoints()
    {
        // Arrange && Act
        var cut = Render(
            @<FluentGrid>
                <FluentGridItem xs="1" sm="2" md="3" lg="4" xl="5" xxl="6">My cell</FluentGridItem>
            </FluentGrid>);

        //Assert
        cut.Verify();
    }

    [Fact]
    public void FluentGrid_Items_JustifyGap()
    {
        // Arrange && Act
        var cut = Render(
            @<FluentGrid>
                <FluentGridItem xs="1" Justify="JustifyContent.Center" Gap="10px">My cell</FluentGridItem>
            </FluentGrid>);

        //Assert
        cut.Verify();
    }

    [Fact]
    public void FluentGrid_Items_NoBreapoint()
    {
        // Arrange && Act
        var cut = Render(
            @<FluentGrid>
                <FluentGridItem Style="min-width: 200px;">My cell</FluentGridItem>
            </FluentGrid>);

        //Assert
        cut.Verify();
    }

    #pragma warning disable xUnit1025 
    [Theory]
    [InlineData(GridItemHidden.Xs, "xs")]
    [InlineData(GridItemHidden.Sm, "sm")]
    [InlineData(GridItemHidden.Md, "md")]
    [InlineData(GridItemHidden.Lg, "lg")]
    [InlineData(GridItemHidden.Xl, "xl")]
    [InlineData(GridItemHidden.Xxl, "xxl")]
    [InlineData(GridItemHidden.XsAndDown, "xs")]
    [InlineData(GridItemHidden.SmAndDown, "xs sm")]
    [InlineData(GridItemHidden.MdAndDown, "xs sm md")]
    [InlineData(GridItemHidden.LgAndDown, "xs sm md lg")]
    [InlineData(GridItemHidden.XlAndDown, "xs sm md lg xl")]
    [InlineData(GridItemHidden.XxlAndDown, "xs sm md lg xl xxl")]
    [InlineData(GridItemHidden.XsAndUp, "xs sm md lg xl xxl")]
    [InlineData(GridItemHidden.SmAndUp, "sm md lg xl xxl")]
    [InlineData(GridItemHidden.MdAndUp, "md lg xl xxl")]
    [InlineData(GridItemHidden.LgAndUp, "lg xl xxl")]
    [InlineData(GridItemHidden.XlAndUp, "xl xxl")]
    [InlineData(GridItemHidden.XxlAndUp, "xxl")]
    public void FluentGrid_Hidden(GridItemHidden hidden, string assert)
    {
        // Arrange && Act
        var cut = Render(
            @<FluentGrid>
                <FluentGridItem HiddenWhen="@hidden">My cell</FluentGridItem>
            </FluentGrid>);

        var hiddenAttribute = cut.Find("div[hidden-when]").GetAttribute("hidden-when") ?? string.Empty;

        // Assert
        Assert.Equal(assert, hiddenAttribute);
    }
    #pragma warning restore xUnit1025

    [Fact]
    public async void FluentGrid_Grid_AdaptiveRendering()
    {
        // Arrange && Act
        var cut = Render(
    @<FluentGrid AdaptiveRendering="true">
        <FluentGridItem HiddenWhen="GridItemHidden.XsAndUp">Cell 1</FluentGridItem>
        <FluentGridItem HiddenWhen="GridItemHidden.XxlAndUp">Cell 2</FluentGridItem>
    </FluentGrid>
    );

        // Simulate screen size Medium
        var grid = cut.FindComponent<FluentGrid>();
        await grid.Instance.FluentGrid_MediaChangedAsync("md");
        grid.Render();

        //Assert
        Assert.DoesNotContain("Cell 1", cut.Markup);
    }

    [Fact]
    public async void FluentGrid_GridItem_AdaptiveRendering()
    {
        // Arrange && Act
        var cut = Render(
    @<FluentGrid>
        <FluentGridItem AdaptiveRendering="true" HiddenWhen="GridItemHidden.XsAndUp">Cell 1</FluentGridItem>
        <FluentGridItem HiddenWhen="GridItemHidden.XxlAndUp">Cell 2</FluentGridItem>
    </FluentGrid>
    );

        // Simulate screen size Medium
        var grid = cut.FindComponent<FluentGrid>();
        await grid.Instance.FluentGrid_MediaChangedAsync("md");
        grid.Render();

        //Assert
        Assert.DoesNotContain("Cell 1", cut.Markup);
    }
}
